package com.cloudcc.mobile.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudcc.cloudframe.adapter.CommonAdapter;
import com.cloudcc.cloudframe.adapter.ViewHolder;
import com.cloudcc.cloudframe.model.MenuTabModel;
import com.cloudcc.mobile.R;
import com.cloudcc.mobile.manager.RunTimeManager;
import com.litesuits.android.log.Log;

import java.lang.reflect.Field;

public class FunGridAdapter extends CommonAdapter<MenuTabModel> {
	public FunGridAdapter(Context mContext) {
		super(mContext);
	}

	@Override
	public void convert(ViewHolder holder, MenuTabModel t) {

//		ImageView bg = holder.getView(R.id.menu_image_bg);
		ImageView icon = holder.getView(R.id.menu_add_icon);
		TextView dropptext = holder.getView(R.id.dropptext);
		TextView name = holder.getView(R.id.menu_add_name);
		name.setText(t.tab_name);
		if("android:approval".equals(t.objId)){
//			Log.d("hahahahahah", t.tabName+"::"+t.objId);
			String o = RunTimeManager.getInstance().getDaiNum();
			if(null!=RunTimeManager.getInstance().getDaiNum()&&(!"0".equals(RunTimeManager.getInstance().getDaiNum()))&&(""!=RunTimeManager.getInstance().getDaiNum())){
				dropptext.setVisibility(View.VISIBLE);
				dropptext.setText(RunTimeManager.getInstance().getDaiNum());
			}else{
				dropptext.setVisibility(View.INVISIBLE);
			}
		}else{
			dropptext.setVisibility(View.INVISIBLE);
		}
		

		try {
			if(t.objId.startsWith("android:addmore")){
				icon.setImageResource(R.drawable.main_cord_addmore);
				return;
			}
			Class drawable = R.drawable.class;
			Log.d("ceshirenwu","获取首页数据"+ t.imageId+":  :"+t.tab_name);
			Field field = drawable.getField(t.imageId);
			int id = field.getInt(field.getName());
			if(id>0){
				icon.setImageResource(id);
			}else{
				icon.setImageResource(R.drawable.cloudtab_weixsld);
			}

//			icon.setBackgroundResource(id);
//			String bgid;
//			if("android:approval".equals(t.objId)){
//				bgid = "add" + (8 % 10);
//			}else{
//			 bgid = "add" + (holder.getPostion() % 10);
//			}
//			Field field2 = drawable.getField(bgid);
//			int bg_id = field2.getInt(field2.getName());
//			bg.setImageBitmap(null);
//			bg.setBackgroundResource(bg_id);
		} catch (Exception e) {
			e.printStackTrace();
			icon.setImageResource(R.drawable.cloudtab_weixsld);
		}

	}

	@Override
	public int getLayoutId() {
		return R.layout.menu_add_item;
	}
	
}
